package com.app.base.dialog;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import com.app.base.R;

public class LoadingFragment extends DialogFragment {

    public LoadingFragment() {

    }

    public static LoadingFragment newInstance() {
        LoadingFragment fragment = new LoadingFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view =inflater.inflate(R.layout.custom_loading_progressbar, container, false);
        ImageView iv_loading = (ImageView) view.findViewById(R.id.iv_loading);
        ValueAnimator animatorFade = ObjectAnimator.ofFloat(iv_loading, "rotation", 0f, 36000f);
        animatorFade.setInterpolator(new LinearInterpolator());
        animatorFade.setDuration(100000);
        animatorFade.setRepeatCount(ValueAnimator.INFINITE);
        animatorFade.start();
        return view;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        return dialog;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }
}
